<template>
  <div class="spaceControl">
    <!-- 空间管理 -->
    <div class="consumerList">
      <div class="chooseContainer padding-box" v-if="role === '1'">
        <el-form ref="searchKey" :model="searchKey" :rules="rules" :inline="true" label-width="80px">
          <el-form-item label="空间名称" prop="spaceName">
            <el-input placeholder="空间名称" v-model="searchKey.spaceName"  class="chooseBox"></el-input>
          </el-form-item>
          <el-form-item label="空间类型" prop="type">
            <el-select v-model="searchKey.type" class="chooseBox" filterable placeholder="空间类型" clearable>
              <el-option v-for="item in typeList" :key="item.value" :label="item.text" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="空间星级" prop="star">
            <el-select v-model="searchKey.star" class="chooseBox" filterable placeholder="空间状态" clearable>
              <el-option v-for="item in starList" :key="item.value" :label="item.text" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="地域分布" prop="city">
            <el-input placeholder="地域分布" v-model="searchKey.city"  class="chooseBox"></el-input>
          </el-form-item>
          <el-form-item label="空间状态" prop="state">
            <el-select v-model="searchKey.state" class="chooseBox" filterable placeholder="空间状态" clearable>
              <el-option v-for="item in stateList" :key="item.value" :label="item.text" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="建筑风格" prop="architecturalStyle">
            <el-input placeholder="建筑风格" v-model="searchKey.architecturalStyle"  class="chooseBox"></el-input>
          </el-form-item>
          <el-form-item label="上架时间">
            <el-form-item prop="startTime">
              <el-date-picker v-model="searchKey.startTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始日期" default-time="00:00:00">
              </el-date-picker>
            </el-form-item>
            <el-form-item prop="endTime">
              <el-date-picker v-model="searchKey.endTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择结束日期" default-time="23:59:59">
              </el-date-picker>
            </el-form-item>
          </el-form-item>
          <br>
          <div class="btnBox">
            <el-button type="primary" class="btnAdd" @click="addSpace">+新增空间</el-button>
            <div class="btnSearch">
              <el-button type="primary" @click="searchSpace">搜索</el-button>
              <el-button @click="spaceClear('searchKey')">重置</el-button>
            </div>
          </div>
        </el-form>
      </div>
      <div class="chooseContainer padding-box" v-if="role === '2'">
        <div class="editorSpace">
          <el-button type="primary" @click="addSpace" style="float:right">+新增空间</el-button>
        </div>
      </div>
      <div class="padding-box">
        <el-table :data="spaceData" style="width: 100%" v-loading="loadingTable" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)" empty-text="暂无相关空间">
          <el-table-column prop="id" label="空间编号" align="center">
          </el-table-column>
          <el-table-column prop="spaceName" label="空间名称" align="center">
          </el-table-column>
          <el-table-column prop="address" label="地址" align="center">
          </el-table-column>
          <el-table-column prop="type" label="空间类型" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.type === 1" style="width:60px;margin:0 auto;">
                <span>民宿</span>
              </div>
              <div v-if="scope.row.type === 2" style="width:60px;margin:0 auto;">
                <span>咖啡馆</span>
              </div>
              <div v-if="scope.row.type === 3" style="width:60px;margin:0 auto;">
                <span>创意空间</span>
              </div>
              <div v-if="scope.row.type === 4" style="width:60px;margin:0 auto;">
                <span>其他</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="cooperationTypes" label="合作类型" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.cooperationTypes === '0'" style="width:60px;margin:0 auto;">
                <span>普通场地</span>
              </div>
              <div v-if="scope.row.cooperationTypes === '1'" style="width:60px;margin:0 auto;">
                <span>会员场地</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="isRecommended " label="推荐类型" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.isRecommended  === 0" style="width:60px;margin:0 auto;">
                <span>未推荐</span>
              </div>
              <div v-if="scope.row.isRecommended  === 1" style="width:60px;margin:0 auto;">
                <span>推荐</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="state" label="状态" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.state === '0'" style="width:60px;margin:0 auto;">
                <span>空间信息上传中</span>
              </div>
              <div v-if="scope.row.state === '1'" style="width:60px;margin:0 auto;">
                <span>待审核</span>
              </div>
              <div v-if="scope.row.state === '2'" style="width:60px;margin:0 auto;">
                <span>审核通过</span>
              </div>
              <div v-if="scope.row.state === '3'" style="width:60px;margin:0 auto;">
                <span>待审核不通过</span>
              </div>
              <div v-if="scope.row.state === '4'" style="width:60px;margin:0 auto;">
                <span>已上架</span>
              </div>
              <div v-if="scope.row.state === '5'" style="width:60px;margin:0 auto;">
                <span>已下架</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" min-width="120">
            <template slot-scope="scope">
              <div class="btn" v-if="role === '1'">
                <div v-show="scope.row.state ==='0'">
                  <!-- <el-button type="text"  size="mini">不可进行操作</el-button> -->
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===1">空间上传到第二步，请继续上传</el-button>
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===2">空间上传到第三步，请继续上传</el-button>
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===3">空间上传到第四步，请继续上传</el-button>
                  <!-- <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===4">空间上传到第四步，请继续上传</el-button> -->
                </div>
                <div v-show="scope.row.state ==='1'">
                  <el-button type="primary" @click="examineDialog(scope.row,scope.$index)" size="mini">审核</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='3'">
                  <el-button type="text" size="mini">审核不通过,请重新上传或修改空间</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='2'">
                  <el-button type="primary" @click="upAndLow(scope.row,'4')" size="mini" v-if="scope.row.state!='4'">上架</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='5'">
                  <el-button type="primary" @click="upAndLow(scope.row,'4')" size="mini" v-if="scope.row.state!='4'">上架</el-button>
                  <el-button type="text" @click="arrangeDate(scope.row)" size="mini">档期</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="setupSpecial(scope.row)" size="mini">设置特价</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                  <el-button type="text" size="mini" @click="deleteConsumer(scope.row)">收入情况</el-button>
                </div>
                <div v-show="scope.row.state ==='4'">
                  <el-button type="primary" @click="upAndLow(scope.row,'5')" size="mini" v-if="scope.row.state!='5'">下架</el-button>
                  <div v-show="scope.row.isRecommended ===0">
                    <el-button type="text" @click="setAndremoveRecommend(scope.row,1)" size="mini" v-if="scope.row.isRecommended!=1">设为推荐</el-button>
                  </div>
                  <div v-show="scope.row.isRecommended ===1">
                    <el-button type="text" @click="setAndremoveRecommend(scope.row,0)" size="mini" v-if="scope.row.isRecommended!=0">移除推荐</el-button>
                  </div>
                  <div v-show="scope.row.cooperationTypes === '0'">
                    <el-button type="text" @click="setAndremoveMember(scope.row,'1')" v-if="scope.row.cooperationTypes!='1'" size="mini">设为会员</el-button>
                  </div>
                  <div v-show="scope.row.cooperationTypes === '1'">
                    <el-button type="text" @click="setAndremoveMember(scope.row,'0')" v-if="scope.row.cooperationTypes!='0'" size="mini">移除会员</el-button>
                  </div>
                  <el-button type="text" @click="arrangeDate(scope.row)" size="mini">档期</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="setupSpecial(scope.row)" size="mini">设置特价</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                  <el-button type="text" size="mini" @click="deleteConsumer(scope.row)">收入情况</el-button>
                </div>
                <el-button type="danger" @click="delSpace(scope.row)" size="mini">删除</el-button>
              </div>
              <div class="btn" v-if="role==='2'">
                <div v-show="scope.row.state ==='0'">
                  <!-- <el-button type="text"  size="mini">不可进行操作</el-button> -->
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===1">空间上传到第二步，请继续上传</el-button>
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===2">空间上传到第三步，请继续上传</el-button>
                  <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===3">空间上传到第四步，请继续上传</el-button>
                  <!-- <el-button type="text" @click="upload(scope.row)" size="mini" v-if="scope.row.addSteps===4">空间上传到第四步，请继续上传</el-button> -->
                </div>
                <div v-show="scope.row.state ==='1'">
                  <el-button type="text" size="mini">待审核</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='2'">
                  <!-- <el-button type="text" size="mini">审核通过</el-button> -->
                  <el-button type="primary" @click="upAndLow(scope.row,'4')" size="mini" v-if="scope.row.state!='4'">上架</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='3'">
                  <el-button type="text" size="mini">审核未通过,请重新上传空间</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                </div>
                <div v-show="scope.row.state ==='5'">
                  <el-button type="primary" @click="upAndLow(scope.row,'4')" size="mini" v-if="scope.row.state!='4'">上架</el-button>
                  <el-button type="text" @click="arrangeDate(scope.row)" size="mini">档期</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                  <el-button type="text" size="mini" @click="deleteConsumer(scope.row)">收入情况</el-button>
                </div>
                <div v-show="scope.row.state ==='4'">
                  <el-button type="primary" @click="upAndLow(scope.row,'5')" size="mini" v-if="scope.row.state!='5'">下架</el-button>
                  <el-button type="text" @click="arrangeDate(scope.row)" size="mini">档期</el-button>
                  <el-button type="text" @click="editSpace(scope.row)" size="mini">修改</el-button>
                  <el-button type="text" @click="seeDetail(scope.row)" size="mini">查看详情</el-button>
                  <el-button type="text" size="mini" @click="deleteConsumer(scope.row)">收入情况</el-button>
                </div>
                <el-button type="danger" @click="delSpace(scope.row)" size="mini">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pageContainer" style="padding-bottom:30px">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="this.pageSizeArray" :page-size="this.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="this.total">
          </el-pagination>
        </div>
      </div>
      <el-dialog title="审核操作" :visible.sync="dialogVisible" :modal="zhezhao" width="30%">
        <span>是否审核通过</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="examineNo">不通过</el-button>
          <el-button type="primary" @click="examine">通过</el-button>
        </span>
      </el-dialog>
      <el-dialog title="删除空间" :visible.sync="dialogVisibleDel" :modal="zhezhao" width="30%">
        <span>是否删除空间</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleDel = false">取消</el-button>
          <el-button type="primary" @click="delSpaceDialog">确定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="查看档期" :visible.sync="dialogVisible1" :modal="zhezhao" width="30%">
        <span style="margin-left:10px">设置档期</span>
        <el-form ref="datesDqForm" :model="datesDqForm" label-width="10px" style="margin-top:15px">
          <el-form-item>
            <el-date-picker type="dates" value-format="yyyy-MM-dd" @change="getSTime" style="width:360px" :picker-options="pickerOptions0" v-model="datesDqForm.dates" placeholder="选择一个或多个日期">
            </el-date-picker>
          </el-form-item>
          <div class="tips" style="margin-bottom:20px;margin-left:10px">
            <span>小提示:选中日期为不可预定日期</span>
          </div>
          <el-form-item>
            <template slot-scope="scope">
              <el-button type="success" @click="dialogVisible1=false" class="refuseBtn actionBtn">取消</el-button>
              <el-button type="primary" @click="updateDates" class="agreeBtn actionBtn">确定</el-button>
            </template>
          </el-form-item>
        </el-form>
      </el-dialog>
      <el-dialog title="特价设置" :visible.sync="specialPrice" @close="closeDialog" :modal="zhezhao" :append-to-body="true" :close-on-press-escape="false">
        <el-form ref="specialPriceForm" :model="specialPriceForm" label-width="100px">
          <el-form-item label="价格设置" prop="price" style="width: 47%;">
            <el-input v-model="specialPriceForm.price" type="number" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="特价商品" prop="shopping" style="">
            <el-select v-model="specialPriceForm.shopping" class="chooseBox" filterable placeholder="空间状态" clearable>
              <el-option v-for="item in shopList" :key="item.value" :label="item.value" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="售卖日期" style="">
            <!-- <el-date-picker v-model="value4" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker> -->
            <el-date-picker v-model="specialPriceForm.startSaleDate" clearable :picker-options="pickerOptions0" value-format="yyyy-MM-dd" type="date" placeholder="选择开始日期">
            </el-date-picker>
            <el-date-picker v-model="specialPriceForm.stopSaleDate" clearable :picker-options="pickerOptions0" type="date" value-format="yyyy-MM-dd" placeholder="选择结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="拍摄日期" style="">
            <el-date-picker v-model="specialPriceForm.startShootingDate" clearable :picker-options="pickerOptions0" value-format="yyyy-MM-dd" type="date" placeholder="选择开始日期">
            </el-date-picker>
            <el-date-picker v-model="specialPriceForm.stopShootingDate" clearable :picker-options="pickerOptions0" value-format="yyyy-MM-dd" type="date" placeholder="选择结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="使用条件" prop="conditions" style="width: 93%;">
            <el-button @click="addCondition" style="margin-left:-0px">新增使用条件</el-button>
            <div v-for="(item, index) in specialPriceForm.conditionList2" :key="index">
              <el-input v-model="item.value" style="width:400px;margin-top:10px" placeholder="提示:可输入'周末节假日不可用','进场人数不超过10人'等"></el-input>
              <el-button @click.prevent="del(item)">删除</el-button>
            </div>
          </el-form-item>
          <div class="tips">
            <span></span>
          </div>
          <el-form-item>
            <template slot-scope="scope">
              <el-button type="success" @click="specialPrice=false" class="refuseBtn actionBtn">取消</el-button>
              <el-button type="primary" @click="agreeApply('specialPriceForm')" class="agreeBtn actionBtn">确定</el-button>
            </template>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
    <version></version>
  </div>
</template>
<script type="text/ecmascript-6">
import { mapGetters } from 'vuex'
import version from '@/base/version/version'
// import { pageCommon } from '@/assets/js/mixin'
export default {
  name: 'spaceControl',
  // mixins: [pageCommon],
  components: {
    version
  },
  data () {
    return {
      apiUrl: '/api/space/showSpaceByCondition',
      pageSizeArray: [10, 20, 30, 40, 50],
      pageNo: 1,
      pageSize: 10,
      pageTotal: null,
      loadingList: false,
      total: 0,
      pickerOptions0: {
        // disabledDate: (time) => {
        //   return time.getTime() < Date.now() - 8.64e7
        // }
        disabledDate (time) {
          let curDate = (new Date()).getTime()
          let three = 90 * 24 * 3600 * 1000
          let threeMonths = curDate + three
          return time.getTime() < Date.now() - 8.64e7 || time.getTime() > threeMonths
        }
      },
      isFirstdata: false,
      isShowPage: true,
      btnText: '上架',
      dialogVisible: false,
      dialogVisible1: false,
      dialogVisibleDel: false,
      zhezhao: false,
      specialPrice: false,
      // userId: this.userInfo.userId,
      role: '',
      loadingTable: true,
      //
      // total: 0,
      typeList: [
        {
          text: '民宿',
          value: 1
        },
        {
          text: '咖啡馆',
          value: 2
        },
        {
          text: '创意空间',
          value: 3
        },
        {
          text: '其他 ',
          value: 4
        }
      ],
      stateList: [
        {
          text: '空间信息上传中',
          value: 0
        },
        {
          text: '待审核',
          value: 1
        },
        {
          text: '审核通过',
          value: 2
        },
        {
          text: '审核未通过',
          value: 3
        },
        {
          text: '上架',
          value: 4
        },
        {
          text: '下架',
          value: 5
        }
      ],
      starList: [
        {
          text: '1星',
          value: 0
        },
        {
          text: '2星',
          value: 1
        },
        {
          text: '3星',
          value: 2
        },
        {
          text: '4星',
          value: 3
        },
        {
          text: '5星',
          value: 4
        }
      ],
      shopList: [
        { value: '不含房间' }, { value: '包含一个房间' }
      ],
      // role: this.userInfo.data.data[0].roleId,
      searchKey: {
        spaceName: '',
        type: '',
        star: '',
        city: '',
        state: '',
        startTime: '',
        endTime: '',
        architecturalStyle: ''
      },
      spaceData: [
      ],
      specialPriceForm: {
        price: '',
        shopping: '',
        startSaleDate: '',
        stopSaleDate: '',
        startShootingDate: '',
        stopShootingDate: '',
        conditionList2: []
      },
      rules: {},
      datesDqForm: {
        dates: []
      }
    }
  },
  computed: {
    ...mapGetters([
      'userInfo'
    ])
    // pickerOptions: {
    //   disabledDate (time) {
    //     return time.getTime() < Date.now() - 8.64e7
    //   }
    // }
  },
  created () {
    // this.searchBtn()
    this.role = this.userInfo.roleId
    console.log(this.userInfo.userId)
    if (!this.noReadayLoading) {
      this.searchBtn()
    }
  },
  watch: {
    pageSize (newVal, oldVal) {
      if (this.pageTotal > newVal) {
        this.searchBtn()
        return false
      }
      if (this.pageTotal < oldVal) {
        return false
      }
      this.searchBtn()
    },
    total (val) {
      if (val === 1) {
        this.isShowPage = false
      } else {
        this.isShowPage = true
      }
    }
  },
  mounted () {
    // this.arrangeDate()
  },
  methods: {
    // 修改每页显示的数据数目
    handleSizeChange (val) {
      this.pageSize = val
      this.searchBtn()
    },
    // 设置pageNo
    handleCurrentChange (val) {
      this.pageNo = val
      this.searchBtn()
    },
    // 上下架
    upAndLow (row, state) {
      row.state = state
      if (row.state === '4') {
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 2,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
          row.state = state
        })
      } else if (row.state === '5') {
        row.state = state
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 1,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            row.isRecommended = 0
            row.cooperationTypes = '0'
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      }
      // this.searchBtn()
    },
    // 审核通过
    examineDialog (row, index) {
      this.dialogVisible = true
      this.id = row.id
      console.log(this.id)
    },
    examine (row, index) {
      this.$axios.post('/api/space/spaceOperation', {
        userId: this.userInfo.userId,
        actionName: 3,
        id: this.id
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchBtn()
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.dialogVisible = false
    },
    // 审核不通过
    examineNo (row, index) {
      this.$axios.post('/api/space/spaceOperation', {
        userId: this.userInfo.userId,
        actionName: 4,
        id: this.id
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchBtn()
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.dialogVisible = false
    },
    // 特价
    setupSpecial (row, index) {
      console.log(row)
      this.specialPrice = true
      this.id = row.id
      this.$axios.post('/api/space/getSpaceDetailsById', {
        id: this.id
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          let asp = res.special
          console.log(asp)
          if (asp.length !== 0) {
            this.specialPriceForm.price = asp[0].price
            this.specialPriceForm.shopping = asp[0].shopping
            this.specialPriceForm.startSaleDate = asp[0].startSaleDate
            this.specialPriceForm.stopSaleDate = asp[0].stopSaleDate
            this.specialPriceForm.startShootingDate = asp[0].startShootingDate
            this.specialPriceForm.stopShootingDate = asp[0].stopShootingDate
            let oo = asp[0].conditions.split(',')
            for (let i = 0; i < oo.length; i++) {
              this.specialPriceForm.conditionList2.push({
                value: oo[i]
              })
            }
            console.log(this.conditionList2)
          } else {
            this.specialPriceForm = {
              price: '',
              shopping: '',
              startSaleDate: '',
              stopSaleDate: '',
              startShootingDate: '',
              stopShootingDate: '',
              conditionList2: []
            }
          }
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.specialPriceForm = {
        price: '',
        shopping: '',
        startSaleDate: '',
        stopSaleDate: '',
        startShootingDate: '',
        stopShootingDate: '',
        conditionList2: []
      }
      // localStorage.clear()
    },
    agreeApply (specialPriceForm) {
      let o = this.specialPriceForm.conditionList2
      if (o.length === 0) {
        this.$message.error('使用条件不可为空')
        return false
      }
      if (this.specialPriceForm.stopSaleDate < this.specialPriceForm.startSaleDate || this.specialPriceForm.stopShootingDate < this.specialPriceForm.startShootingDate) {
        this.$message.error('结束时间不可小于开始时间')
        return false
      }
      // console.log(o)
      let arr = []
      for (let i = 0; i < o.length; i++) {
        arr.push(
          o[i].value
        )
      }
      this.$axios.post('/api/space/setSpaceSpecialMessageById', {
        userId: this.userInfo.userId,
        spaceId: this.id,
        price: this.specialPriceForm.price,
        shopping: this.specialPriceForm.shopping,
        startSaleDate: this.specialPriceForm.startSaleDate,
        stopSaleDate: this.specialPriceForm.stopSaleDate,
        startShootingDate: this.specialPriceForm.startShootingDate,
        stopShootingDate: this.specialPriceForm.stopShootingDate,
        conditions: arr.join(',')
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          // sessionStorage.removeItem('specialPriceForm')
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.specialPrice = false
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.specialPriceForm = {
        price: '',
        shopping: '',
        startSaleDate: '',
        stopSaleDate: '',
        startShootingDate: '',
        stopShootingDate: '',
        conditionList2: []
      }
      // this.$router.go(0)
    },
    // 关闭弹框的事件
    closeDialog () {
      // this.setupSpecial()
      // this.specialPriceForm = '' // 清空数据
    },
    // 新增使用条件
    addCondition (item, index) {
      this.specialPriceForm.conditionList2.push({
        value: ''
      })
    },
    del (item) {
      // var index = this.rooms.indexOf(item)
      // this.rooms.splice(index, 1)
      var index = this.specialPriceForm.conditionList2.indexOf(item)
      if (index !== -1) {
        this.specialPriceForm.conditionList2.splice(index, 1)
      }
    },
    // 推荐
    setAndremoveRecommend (row, isRecommended) {
      if (row.isRecommended === 1) {
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 6,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      } else if (row.isRecommended === 0) {
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 5,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      }
      row.isRecommended = isRecommended
    },
    // 设置移除会员
    setAndremoveMember (row, cooperationTypes) {
      if (row.cooperationTypes === '1') {
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 8,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      } else if (row.cooperationTypes === '0') {
        this.$axios.post('/api/space/spaceOperation', {
          userId: this.userInfo.userId,
          actionName: 7,
          id: row.id
        }).then(response => {
          const res = response.data
          if (res.code === '00000000') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      }
      row.cooperationTypes = cooperationTypes
    },
    // 档期
    arrangeDate (row) {
      this.id = row.id
      this.$axios.post('/api/space/showSpaceScheduleById', {
        id: this.id
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          console.log(res.calendar)
          for (let i = 0; i < res.calendar.length; i++) {
            console.log(res.calendar[i])
            this.datesDqForm.dates.push(
              res.calendar[i]
            )
          }
          // this.datesDqForm.dates = res.calendar
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.datesDqForm = {
        dates: []
      }
      this.dialogVisible1 = true
    },
    updateDates () {
      this.$axios.post('/api/space/updateSpaceScheduleById', {
        id: this.id,
        calendar: this.datesDqForm.dates,
        userId: this.userInfo.userId
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.dialogVisible1 = false
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.datesDqForm = {
        dates: []
      }
    },
    getSTime (val) {
      this.datesDqForm.dates = val // 这个sTime是在data中声明的，也就是v-model绑定的值
    },
    addSpace () {
      this.$router.push({ name: 'spaceControl/addSpace' })
    },
    seeDetail (row) {
      this.$router.push({ name: 'spaceControl/spaceDetail', query: { spaceId: row.id } })
    },
    searchBtn () {
      this.$axios.post('/api/space/showSpaceByCondition',
        {
          userId: this.userInfo.userId,
          star: this.searchKey.star,
          state: this.searchKey.state,
          spaceName: this.searchKey.spaceName,
          city: this.searchKey.city,
          startTime: this.searchKey.startTime,
          type: this.searchKey.type,
          endTime: this.searchKey.endTime,
          architecturalStyle: this.searchKey.architecturalStyle,
          pageNo: this.pageNo,
          pageSize: this.pageSize
        }
      ).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.loadingTable = false
          let arr = res.results
          console.log(arr)
          let spaceList = []
          for (let i = 0; i < arr.length; i++) {
            spaceList.push({
              id: arr[i].id,
              spaceName: arr[i].spaceName,
              address: arr[i].address,
              type: arr[i].type,
              state: arr[i].state,
              cooperationTypes: arr[i].cooperationTypes,
              isRecommended: arr[i].isRecommended,
              addSteps: arr[i].addSteps
            })
          }
          this.spaceData = [...spaceList]
          this.total = res.total
        }
      })
    },
    searchSpace () {
      this.$axios.post('/api/space/showSpaceByCondition',
        {
          userId: this.userInfo.userId,
          star: this.searchKey.star,
          state: this.searchKey.state,
          spaceName: this.searchKey.spaceName,
          city: this.searchKey.city,
          startTime: this.searchKey.startTime,
          type: this.searchKey.type,
          endTime: this.searchKey.endTime,
          architecturalStyle: this.searchKey.architecturalStyle,
          pageNo: 1,
          pageSize: this.pageSize
        }
      ).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.loadingTable = false
          let arr = res.results
          console.log(arr)
          let spaceList = []
          for (let i = 0; i < arr.length; i++) {
            spaceList.push({
              id: arr[i].id,
              spaceName: arr[i].spaceName,
              address: arr[i].address,
              type: arr[i].type,
              state: arr[i].state,
              cooperationTypes: arr[i].cooperationTypes,
              isRecommended: arr[i].isRecommended,
              addSteps: arr[i].addSteps
            })
          }
          this.spaceData = [...spaceList]
          this.total = res.total
        }
      })
    },
    spaceClear (searchKey) {
      this.$nextTick(() => {
        if (this.$refs[searchKey] !== undefined) {
          this.$refs[searchKey].resetFields()
        }
        this.searchBtn()
      })
    },
    editSpace (row) {
      this.$router.push({ name: 'spaceControl/incomeDrtail', query: { spaceId: row.id } })
    },
    exportOrder () { },
    deleteConsumer (row) {
      console.log(row.id)
      this.$router.push({ name: 'orderControl', query: { spaceId: row.id } })
    },
    upload (row) {
      this.$router.push({ name: 'spaceControl/addSpace', query: { id: row.id, addSteps: row.addSteps, type: row.type, t: Date.now() } })
    },
    delSpace (row) {
      this.dialogVisibleDel = true
      this.id = row.id
    },
    delSpaceDialog (row) {
      this.$axios.post('/api/space/deleteSpace', {
        id: this.id,
        userId: this.userInfo.userId
      }).then(response => {
        const res = response.data
        if (res.code === '00000000') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchBtn()
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
      this.dialogVisibleDel = false
    }
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
@import '../../../../assets/stylus/variable'
.chooseContainer
  background $bg-normal
  overflow hidden
  display flex
  width 100%
  padding $spacing
  padding-bottom 20px
  flex-wrap wrap
  box-sizing border-box
  .chooseBox
    flex 0 0 224px
    margin-right $spacing
    margin-bottom $spacing
  .editorSpace
    // margin-left 93.5%
    width 100%
    margin-top 10px
    // display flex
    // justify-content center
  .btnBox
    display flex
    justify-content space-between
</style>
